﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZhouYu.DreamTour.BLL.IService;
using ZhouYu.DreamTour.Model;
using ZhouYu.DreamTour.Romote;
using ZhouYu.DreamTour.ViewModel;
using ZhouYu.DreamTour.Web.Models;

namespace ZhouYu.DreamTour.Web.Controllers
{
    public class HotelController : Controller
    {
        private IHotelService _hotelService;
        private ISmsInfoService _smsInfoService;
        public HotelController(IHotelService hotelService, ISmsInfoService smsInfoService)
        {
            _hotelService = hotelService;
            _smsInfoService = smsInfoService;
        }


        /// <summary>
        /// 根据酒店Id获取房间类型
        /// </summary>
        /// <returns></returns>
        public JsonResult GetRoom_TypeByHotelId(int HotelId)
        {
            //调用根据酒店Id获取房间类型
            ResponseResult responseResult = _hotelService.GetRoom_TypeByHotelId(HotelId);
            return Json(responseResult);
        }

        /// <summary>
        /// 添加酒店预定信息
        /// </summary>
        /// <returns></returns>
        public JsonResult AddHotelOrderInfo(HotelOrder hotelOrder,string Order_No)
        {
            //从Session获取当前登录账号的User_Id
            hotelOrder.User_Id = UserInfoContext.userInfoContext.UserInfo.User_Id;
            //调用添加酒店预定信息
            ResponseResult responseResult = _hotelService.AddHotelOrderInfo(hotelOrder,Order_No);
            //调用根据酒店Id获取酒店名称
            string hotelName = _hotelService.GetHotelName(hotelOrder.HotelId);
            //判断是否预定成功
            if (responseResult.Success)
            {
                //调用发送酒店预定短信方法，接收是否成功返回值
                responseResult = _smsInfoService.SendHotelSms(hotelOrder.Telphone.ToString(), hotelOrder.User_Name, hotelName);
            }
            return Json(responseResult);
        }
    }
}